package com.hxzy.controller.unit;

import com.alibaba.fastjson.JSONObject;
import com.hxzy.util.ThreadLocalUtil;
import com.hxzy.common.BaseServlet;
import com.hxzy.common.ResultAjax;
import com.hxzy.entity.Unit;
import com.hxzy.service.UnitService;
import com.hxzy.service.impl.UnitServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @Author: lqq
 * @Description:
 * @Date: 2022/3/8 16:43
 */
@WebServlet(urlPatterns = "/unit/deleteJson")
public class DeleteJson extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        ThreadLocalUtil.threadLocal.get();
        try {
            Unit unit = super.CollectiongParameterToJSON(req, Unit.class);
            UnitService service=new UnitServiceImpl();
            int delete = service.delete(unit.getId());
            ResultAjax resultAjax=null;
            if (delete>0){
                resultAjax = ResultAjax.success("删除成功");
            }else {
                resultAjax =ResultAjax.error("删除失败");
            }
            super.render(resp, JSONObject.toJSONString(resultAjax));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
